package com.wushi.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.wushi.domain.BookBorrow;
import com.wushi.service.IBookBorrowService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 书籍借阅Controller
 * 
 * @author wushi
 * @date 2024-11-19
 */
@Controller
@RequestMapping("/bisiness/borrow")
public class BookBorrowController extends BaseController
{
    private String prefix = "bisiness/borrow";

    @Autowired
    private IBookBorrowService bookBorrowService;

    @RequiresPermissions("bisiness:borrow:view")
    @GetMapping()
    public String borrow()
    {
        return prefix + "/borrow";
    }

    /**
     * 查询书籍借阅列表
     */
    @RequiresPermissions("bisiness:borrow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BookBorrow bookBorrow)
    {
        startPage();
        List<BookBorrow> list = bookBorrowService.selectBookBorrowList(bookBorrow);
        return getDataTable(list);
    }

    /**
     * 导出书籍借阅列表
     */
    @RequiresPermissions("bisiness:borrow:export")
    @Log(title = "书籍借阅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BookBorrow bookBorrow)
    {
        List<BookBorrow> list = bookBorrowService.selectBookBorrowList(bookBorrow);
        ExcelUtil<BookBorrow> util = new ExcelUtil<BookBorrow>(BookBorrow.class);
        return util.exportExcel(list, "书籍借阅数据");
    }

    /**
     * 新增书籍借阅
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存书籍借阅
     */
    @RequiresPermissions("bisiness:borrow:add")
    @Log(title = "书籍借阅", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BookBorrow bookBorrow)
    {
        return toAjax(bookBorrowService.insertBookBorrow(bookBorrow));
    }

    /**
     * 修改书籍借阅
     */
    @RequiresPermissions("bisiness:borrow:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BookBorrow bookBorrow = bookBorrowService.selectBookBorrowById(id);
        mmap.put("bookBorrow", bookBorrow);
        return prefix + "/edit";
    }

    /**
     * 修改保存书籍借阅
     */
    @RequiresPermissions("bisiness:borrow:edit")
    @Log(title = "书籍借阅", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BookBorrow bookBorrow)
    {
        return toAjax(bookBorrowService.updateBookBorrow(bookBorrow));
    }

    /**
     * 删除书籍借阅
     */
    @RequiresPermissions("bisiness:borrow:remove")
    @Log(title = "书籍借阅", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bookBorrowService.deleteBookBorrowByIds(ids));
    }
}
